package com.git.bds.mr.hospital.controller;

import com.git.bds.mr.doctor.model.domain.Doctor;
import com.git.bds.mr.hospital.convert.DoctorConvert;
import com.git.bds.mr.hospital.convert.SectorConvert;
import com.git.bds.mr.hospital.model.domain.Sector;
import com.git.bds.mr.hospital.model.vo.DoctorVO;
import com.git.bds.mr.hospital.model.vo.SectorVO;
import com.git.bds.mr.hospital.service.sector.SectorService;
import com.git.bds.mr.page.PageParam;
import com.git.bds.mr.page.PageResult;
import com.git.bds.mr.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 科室表 前端控制器
 * </p>
 *
 * @author 成大事
 * @since 2022-09-19 16:43:59
 */
@Api(tags = "科室 管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/hospital/sector")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SectorController {

    private final SectorService sectorService;

    @GetMapping("/getAllSector")
    @ApiOperation("获取科室列表")
    public R<List<SectorVO>> getAllSector(){
        List<Sector> sectorList = sectorService.getAllSector();
        return R.ok(SectorConvert.INSTANCE.toSectorVO(sectorList));
    }


    @PostMapping("/getAllSectorPage")
    @ApiOperation("获取科室列表 分页")
    public R<PageResult<SectorVO>> getAllSectorPage(@Validated @RequestBody PageParam pageParam){
        return R.ok(sectorService.getAllSectorPage(pageParam));
    }

    @PostMapping("/getAllDoctors/{sectorId}")
    @ApiOperation("获取此科室下所有医生")
    @ApiImplicitParam(name = "sectorId", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public R<List<DoctorVO>> getAllDoctors(
            @PathVariable("sectorId") Long sectorId
    ){
        List<Doctor> doctorList = sectorService.getAllDoctors(sectorId);
        return R.ok(DoctorConvert.INSTANCE.toDoctorVO(doctorList));
    }

    @PostMapping("/getAllDoctorsPage/{sectorId}")
    @ApiOperation("获取此科室下所有医生  分页")
    @ApiImplicitParam(name = "sectorId", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public R<PageResult<DoctorVO>> getAllDoctorsPage(
            @Validated @RequestBody PageParam pageParam,
            @PathVariable("sectorId") Long sectorId
    ){
        return R.ok(sectorService.getAllDoctorsPage(pageParam,sectorId));
    }


}
